package org.kisekiproject.pages.kpimeters
{
	import flash.display.MovieClip;
	
	public class KpiMeters extends MovieClip
	{
		// FLA
		public var meterHolder:MovieClip;

		private var _meterClips:Array;

		[Property(arrayType="org.kisekiproject.pages.kpimeters.MeterInfo")]
		public function set meters(value:Array) {
			trace("setting meters..");
			if (!_meterClips)
				createMeters(value.length);

			for (var i:int=0; i<_meterClips.length; i++) {
				var meterInfo:MeterInfo=value[i];
				var clip:MovieClip=_meterClips[i];

				clip.labelField.text=meterInfo.label;

				var val:Number=meterInfo.value;
				if (val<0) val=0;
				if (val>1) val=1;
				clip.arrowClip.rotation=-200+220*val;
			}
		}
		
		/**
		 * Create meters.
		 */
		private function createMeters(count:int):void {
			_meterClips=new Array();

			var xPos:int=0;

			for (var i:int=0; i<count; i++) {
				var meterClip:MovieClip=new KpiMeter();
				meterHolder.addChild(meterClip);
				_meterClips.push(meterClip);
				meterClip.x=xPos;

				xPos+=120;
			}
		}
	}
}